#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double r = 6371009;
const double PI = 3.1415926;
int main(int argc, char** argv) {
    double a,b,c,d;
    int T;
    cin>>T;
    while (T--) {
        cin>>a>>b>>c>>d;
        double p = abs(a-c)*PI/180;
        double q = abs(b-d)*PI/180;
        double sp = sin(p);
        double sq = sin(q);
        double cp = cos(p)-cos(q);
        double res = r * sqrt(sp*sp+sq*sq+cp*cp);
        printf("%lf\n", res);
    }
    return 0;
}
